<?php

namespace app\model\course\topic;

use app\model\TimeModel;

class Topic extends TimeModel
{
    protected $table = 'sj_topic';
    protected $json = ['answer'];
    protected $jsonAssoc = true;

    public static function examTopic($ids ='' , $point = 0)
    {
       $list = Topic::where('id' , 'in' , $ids)
           ->field('id,title,type,a,b,c,d,e,f,answer,desc')->select()->toArray();
       foreach ($list as $k=>$val){
           $option = [] ;
           if($val['a'] != ''){
               $option[] = ['id' => 'A' , 'title' => $val['a'] ] ;
           }
           if($val['b'] != ''){
               $option[] = ['id' => 'B' , 'title' => $val['b'] ] ;
           }
           if($val['c'] != ''){
               $option[] = ['id' => 'C' , 'title' => $val['c'] ] ;
           }
           if($val['d'] != ''){
               $option[] = ['id' => 'D' , 'title' => $val['d'] ] ;
           }
           if($val['e'] != ''){
               $option[] = ['id' => 'E' , 'title' => $val['e'] ] ;
           }
           if($val['f'] != ''){
               $option[] = ['id' => 'F' , 'title' => $val['f'] ] ;
           }
           unset($list[$k]['a'] ,$list[$k]['b'] ,$list[$k]['c'] ,$list[$k]['d'] ,$list[$k]['e'] ,$list[$k]['f'] ) ;
           $list[$k]['sub'] = $option ;
           $list[$k]['point'] = $point ;
       }
       return $list ;
    }
}